package org.example.mapper;

import org.example.common.entity.ProductDiscount;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ProductDiscountMapper {

    // 插入一条商品折扣关联记录
    @Insert("INSERT INTO product_discount (product_id, discount_id) VALUES (#{productId}, #{discountId})")
    int insert(ProductDiscount productDiscount);

    // 根据商品 ID 查询关联的折扣记录
    @Select("SELECT * FROM product_discount WHERE product_id = #{productId} AND is_deleted = 0")
    List<ProductDiscount> selectByProductId(@Param("productId") Long productId);

    // 根据折扣 ID 查询关联的商品记录
    @Select("SELECT * FROM product_discount WHERE discount_id = #{discountId} AND is_deleted = 0")
    List<ProductDiscount> selectByDiscountId(@Param("discountId") Long discountId);

    // 根据商品 ID 和折扣 ID 删除关联记录
    @Delete("DELETE FROM product_discount WHERE product_id = #{productId} AND discount_id = #{discountId}")
    int deleteByProductIdAndDiscountId(@Param("productId") Long productId, @Param("discountId") Long discountId);
}